package com.md.domain.model.po;

import com.baomidou.mybatisplus.annotation.TableName;
import com.google.common.collect.Maps;
import com.md.base.IBasePO;
import com.md.util.ObjectUtil;
import com.md.util.StringUtil;
import com.md.value.ModuleConstants;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * 应用类
 *
 * @author 刘骄阳
 * @date 2024/12/7 0:24
 **/
@EqualsAndHashCode(callSuper = true)
@Data
@TableName("`t_app_info`")
public class AppInfoPO extends IBasePO {
  /**
   * 应用code
   */
  private String appCode;
  /**
   * 应用名
   */
  private String appName;
  /**
   * 应用英文名
   */
  private String appEnName;
  /**
   * 额外参数
   */
  private String appExtra;
  /**
   * 应用logo
   */
  private String appLogo;
  /**
   * 应用类型(0: 公开; 1: 私有)
   */
  private Integer appType;
  /**
   * 创建人id
   */
  private String userId;

  public void buildExtra() {
    Map<String, Object> extra = Maps.newHashMap();
    if (ObjectUtil.notEmpty(appExtra)) {
      extra = StringUtil.jsonToMap(appExtra);
    }
    Long expireTime = (Long) extra.get(ModuleConstants.EXPIRE_TIME);
    TimeUnit timeUnit = (TimeUnit) extra.get(ModuleConstants.TIME_UNIT);
    if (ObjectUtil.isEmpty(expireTime) || ObjectUtil.isEmpty(timeUnit)) {
      extra.put(ModuleConstants.EXPIRE_TIME, ModuleConstants.DEFAULT_EXPIRE_TIME);
      extra.put(ModuleConstants.TIME_UNIT, ModuleConstants.DEFAULT_TIME_UNIT);
      appExtra = StringUtil.objectToJson(extra);
    }
  }
}
